
import conf from '../config/userconf.js'
export default{
    data(){
        return{
            list:[],  //列表数据
            searchData:{ //查询
                anm_branch_name:''
            },
            tableData: {
                id:'',
                name:'',
                type:'',
                module_id:'',
                
            }
        }
    },
    filters:{

    },
    methods:{
        /* 列表*/
        getList (data=null){
            conf.management.authorityList(data,(state,res)=>{
                if (state == 'success'&&res.data.code == 0){
                    console.log(res);
                    this.list = res.data.data.data
                }
            })
        },
        // 修改权限
        authorityEdit(row,data=Object()){
            this.$prompt('修改权限', {
                inputPlaceholder:'请输入权限名称',
                inputValue: row.name,
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(({ value }) => {
                data.name = value;
                data.id = row.id;
                conf.management.authorityEdit(data,(state,res)=>{
                    if(state == 'success'&&res.data.code == 0){
                        console.log(res);
                        this.getList();
                        this.$message({
                            type: 'success',
                            message: '修改成功'
                        });
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消修改'
                });       
            });

        },
        
        // 添加权限
        authorityAdd(data=null){
            this.$prompt('添加权限', {
                inputPlaceholder:'请输入权限名称',
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(({ value }) => {
                data.name = value;  //权限id
                conf.management.authorityAdd(data,(state,res)=>{
                    if(state == 'success'&&res.data.code == 0){
                        this.getList();
                        this.$message({
                            type: 'success',
                            message: '添加成功'
                        });
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消添加'
                });       
            });
            

        },
        // 删除权限
        authorityDel(row,data=Object()){
             this.$confirm('确认删除权限 "'+row.name+'" ?', '删除权限', {  
                 confirmButtonText: '确定',
                 cancelButtonText: '取消',
                 type: 'warning'
             }).then(() => {
                 data.id = row.id;    //权限id
                 conf.management.authorityDel(data,(state,res)=>{
                     if(state == 'success'&&res.data.code == 0){
                         console.log(res);
                         this.getList();
                         this.$message({
                             type: 'success',
                             message: '删除成功!'
                         });
                     }else if(state == 'success'&&res.data.code != 0){
                         this.$message({
                             type: 'info',
                             message: res.data.msg
                         });
                     }
                 })
             }).catch(() => {
                 this.$message({
                   type: 'info',
                   message: '已取消删除'
                 });          
             });
         },
        handleClick(row) {
            console.log(row);
        },
        /*查询 */
        search () {
            let data  = this.searchData;

            this.getList(data)
            // this.$router.push({name:'pay'})
        }
    },
    mounted (){
        this.$nextTick(function(){
            this.getList()
        })
    },
}